import fs from "fs";
import sqlite3 from "sqlite3";

export default function (callback: (isInit: boolean) => void) {
  const mode = process.env.MODE;
  const path = process.env.DATABASE_PATH;
  const dbPath = `${path}/${mode}.db`;
  const isInit = fs.existsSync(dbPath);
  if (mode === "dev") {
    sqlite3.verbose();
  }
  return new sqlite3.Database(dbPath, (err) => {
    if (err) {
      console.error("连接数据库时出错:", err);
    } else {
      callback(isInit);
    }
  });
}
